<?php
/***
 * 描述：商品查询
 * @category		Mobile		
 * @package			Action			
 * @subpackage		
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-4-6
 * @version			$Id: ProductAction.class.php 85 2013-12-07 01:02:19Z whtaok@gmail.com $
 */
class ProductAction extends WwwAction {
	
	/**
	 * 描述：初始化模块
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected  function _initialize() {
		parent::_initialize();
	}
	
	/**
	 * 描述：商品列表：店铺，分类，名称进行筛选
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function indexAct() {
		$cate_data = $this->_filterCate();
		if(!cate_data){
			$this->error('未有符合条件的商品');
		}
		$search = array(
						'cate_code'=> $cate_data['cate_code'],
						'name'=>I('name'),
						'brand'=>I('brand'),
				);
		//取商品
		$mod = new ProductPriceViewModel();
		list($prodData['list'],$prodData['page']) = $mod->findListPage($this->curr_shop_id,$search);
		foreach ($prodData['list'] as $key => $value){
			$prodData['list'][$key]['pic']=m_prod_pic($value['prod_id']);
			$prodData['list'][$key]['spec']=m_prod_spec($value['spec'],$value['spec_qty'],$value['spec_unit']);
		}
		//取分类
		$cate_codes = split("-", $search['cate_code']);
		//页面显示品牌信息
		$search['cate_brands'] = $mod->findCateBrandList($this->curr_shop_id, $cate_codes);
		//页面显示分类信息
		foreach($cate_codes as $val){
			$search['cate_item'][$val] = m_get_cate_code($val); 
		}
		//页面显示汇总分类信息
		if($cate_data['pcate']){
			$search['pcate'] = $cate_data['pcate'];
			$search['pcate_name'] = $cate_data['name'];
		}
		$this->assign('search',$search);
		$this->assign('prodData',$prodData);
		$this->display('index');
	}
	/**
	 * 描述：显示推广商品列表
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showListPageAct(){
		$search = array(
				'cate_code'=> I('cate_code'),
				'name'=>I('name'),
				'brand'=>I('brand'),
				'spread'=>I('spread'),
		);
		switch($search['spread']){
			case 'hot':
				$search['is_hot'] = 1;
				break;
			case 'rmd':
				$search['is_rmd'] = 1;
				break;
			case 'new':
				$search['is_new'] = 1;
				break;
			case 'frn':
				$search['is_frn'] = 1;
				break;
		}
		$mod = new ProductPriceViewModel();
		list($prodData['list'],$prodData['page']) = $mod->findListPage($this->curr_shop_id,$search,'ordlist');
		
		foreach ($prodData['list'] as $key => $value){
			$prodData['list'][$key]['pic']=m_prod_pic($value['prod_id']);
			$prodData['list'][$key]['spec']=m_prod_spec($value['spec'],$value['spec_qty'],$value['spec_unit']);
		}
		$this->assign('search',$search);
		$this->assign('prodData',$prodData);
		$this->display('spread');
	}
	
	/**
	 * 描述：显示套餐相关
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showCyListPageAct(){
		$search = array(
				'spread'=>I('spread'),
		);
		switch($search['spread']){
			case 'swtc':
				$search['cate_code'] = 'D1';
				break;
			case 'fbss':
				$search['cate_code'] = 'A101-A102';
				$search['stock_prod_id'] = 0;
				break;
			case 'pcyl':
				$search['cate_code'] = 'B101-B102-B107-B108-B109';
				$search['stock_prod_id'] = 0;
				break;
			case 'chls':
				$search['cate_code'] = 'A103-A106';
				$search['stock_prod_id'] = 0;
				break;
		}
		$mod = new ProductPriceViewModel();
		list($prodData['list'],$prodData['page']) = $mod->findListPage($this->curr_shop_id,$search);
	
		foreach ($prodData['list'] as $key => $value){
			$prodData['list'][$key]['pic']=m_prod_pic($value['prod_id']);
			$prodData['list'][$key]['spec']=m_prod_spec($value['spec'],$value['spec_qty'],$value['spec_unit']);
		}
		$this->assign('search',$search);
		$this->assign('prodData',$prodData);
		$this->display('cy');
	}	
	/**
	 * 描述：加载商品列表
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function listAct(){
		$search = array(
				'cate_code'=> I('cate_code'),
				'name'=>I('name'),
				'brand'=>I('brand'),
		);
		$mod = new ProductPriceViewModel();
		list($list,$page) = $mod->findListPage($this->curr_shop_id,$search);
		
		foreach ($list as $key => $value){
			$list[$key]['pic']=m_prod_pic($value['prod_id']);
			$list[$key]['spec']=m_prod_spec($value['spec'],$value['spec_qty'],$value['spec_unit']);
		}
		$this->ajaxReturn(array('list'=>$list,'page'=>$page));
	}
	/**
	 * 描述：过滤cate 返回   数组  array('A101'=>'休闲零食');
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	private function _filterCate(){
		$pcate = I('pcate');			//汇总分类 PA PB PC
		$cate_code = I('cate_code');	//单分类	A B C
		if($cate_code){
			$cate_name = m_get_cate_code($cate_code);
			$rtnData = array(
					'cate_code'=>$cate_code,
					'name'=>$cate_name,
					'pcate'=>'',
				);
			return $rtnData;
		}
		
		if($pcate){
			$pcate_list = m_get_pcate();
			//判断是否是正确的分类
			$cate_data = $pcate_list[$pcate];
			if($cate_data){
				$rtnData = array(
						'cate_code'=>$cate_data['cate_code2'],
						'name'=>$cate_data['name'],
						'pcate'=>$pcate,
				);
				return $rtnData;
			}
		}
		return null;
	}


}

?>